package com.ity.teamanagement.controller;

import com.ity.teamanagement.annocation.CheckAuthorityStatus;
import com.ity.teamanagement.result.Result;
import com.ity.teamanagement.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author coderFu
 * @create 2021/6/2
 */
@RestController
@Api(tags = "后台文件模块")
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService fileService;

    @PostMapping("/uploadTeaImg")
    @ApiOperation("上传茶种图片")
    @CheckAuthorityStatus
    public Result uploadTeaImg(@RequestParam("file") MultipartFile multipartFile, @RequestParam(value = "imgType") Long imgType, @RequestParam(value = "keyId",required = false)Long keyId){
        return Result.success(fileService.saveImg(multipartFile,imgType,keyId));
    }

    @DeleteMapping("/deleteTeaImg")
    @ApiOperation("删除茶种图片")
    @CheckAuthorityStatus
    public Result deleteTeaImg(@RequestParam("id")Long id){
        return Result.success(fileService.deleteTeaImg(id));
    }

    @PostMapping("/uploadOtherImg")
    @ApiOperation("上传其它图片（备注图片，封面图等）")
    @CheckAuthorityStatus
    public Result uploadOtherImg(@RequestParam("file") MultipartFile multipartFile,@RequestParam(value = "keyId",required = false) Long keyId){
        return Result.success(fileService.uploadOtherImg(multipartFile,keyId));
    }

    @DeleteMapping("/deleteOtherImg")
    @ApiOperation("删除其它图片")
    @CheckAuthorityStatus
    public Result deleteOtherImg(@RequestParam("id") Long id){
        return Result.success(fileService.deleteOtherImg(id));
    }
}
